home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / _archive / utils / graphics / convrtrs / amiga / dgvcon.arc / DGIFF.C next >
C/C++ Source or Header  |  1990-10-18  |  4KB  |  139 lines

  1. /* DgIFF.c */
  2.  
  3. /* Part of DgvCon by Jim Omura */
  4.  
  5. /* Converts one Imagewise line to 6 bit planes of IFF/ILBM.
  6.  * An Imagewise line has 256 pixels.  That will convert to
  7.  * 16 words (each with one bit from each of 16 pixels)
  8.  * per bit plane.  The lowest order bit plane is stored
  9.  * first.
  10.  */
  11.  
  12. #include "dgvcon.h"
  13.  
  14. toiff()
  15. {
  16.  
  17.     extern int      bright;             /* Brightness */
  18.     extern int      contrast;
  19.     extern int      inlen;              /* Input buffer length */
  20.     extern int      planes;             /* Bit Planes */
  21.     extern int      white;              /* White value */
  22.  
  23.     extern unsigned char inbuf[640];     /* Input File buffer */
  24.     extern USHORT        outbuf[320];     /* Output File buffer */
  25.     extern IFFBMHDR hdrstr;
  26.  
  27.     int             blkcntr;
  28.     int             blklim;    /* Number of 16 Pixel blocks per line */
  29.     int             plcntr;    /* Bit plane counter */
  30.     int             ccntr;
  31.     int             greyval;
  32.     register USHORT iffword;
  33.     char            *inbyte;   /* Input Byte pointer */
  34.     int             skipcntr;  /* Unused bitplanes to be skipped */
  35.  
  36. /* Adjust Grey Scale: */
  37.  
  38.     if((contrast != 100) || (bright != 0))
  39.     {
  40.  
  41.         ccntr = 0;
  42.         inbyte = (char *)inbuf;
  43.         for(;;)
  44.         {
  45.             if (ccntr == inlen)
  46.             {
  47.                 break;
  48.             }
  49.             greyval = ((((unsigned) *inbyte) + bright) * contrast) / 100;
  50.  
  51.             if (greyval > white)  /* Boundary Checking */
  52.             {
  53.                 greyval = white;
  54.             }
  55.             else
  56.             {
  57.                 if (greyval < 0)
  58.                 {
  59.                     greyval = 0;
  60.                 }
  61.             }
  62.  
  63.             *inbyte = (char) greyval;
  64.             ++inbyte;                 /* Next byte */
  65.             ++ccntr;
  66.  
  67.         }   /* Endloop Adjust Brightness & Contrast */
  68.  
  69.     }   /* Endif not default brightness or contrast */
  70.  
  71. /* IFF Conversion */
  72.  
  73. /* Skip unused Bitplanes: */
  74.     ccntr = 0;
  75.     skipcntr = 8 - planes;
  76.     if (skipcntr > 0)
  77.     {
  78.         for(;;)
  79.         {
  80.             if(ccntr == inlen)
  81.             {
  82.                 break;
  83.             }
  84.             inbuf[ccntr] = inbuf[ccntr] >> skipcntr;
  85.             ++ccntr;
  86.  
  87.         }   /* Endloop Adjust bytes */
  88.  
  89.     }   /* Endif Skip Bitplanes */
  90.  
  91. /* Convert line to IFF: */
  92.  
  93.     blklim = hdrstr.bm_w / 16; /* 320 line is 20, 640 line is 40 */
  94.     plcntr = 0;
  95.     for(;;)
  96.     {
  97.         if(plcntr == planes)
  98.         {
  99.             break;
  100.         }   /* Endif */
  101.  
  102.         blkcntr = 0;
  103.         inbyte = (char *)inbuf;
  104.         for (;;)
  105.         {
  106.  
  107.             if(blkcntr == blklim)
  108.             {
  109.                 break;
  110.             }   /* Endif */
  111.  
  112.             ccntr = 0;
  113.             for(;;)
  114.             {
  115.  
  116.                 if (ccntr == 16)
  117.                 {
  118.                     break;
  119.                 }   /* Endif */
  120.                 iffword = (iffword << 1);
  121.                 iffword = (iffword + (*inbyte & 1));
  122.                 (*inbyte) = (*inbyte >> 1);
  123.                 ++ccntr;
  124.                 ++inbyte;             /* Point to next Input byte */
  125.             }   /* Endloop convert block */
  126.  
  127.             outbuf[(blklim * plcntr) + blkcntr] = iffword;
  128.             ++blkcntr;
  129.  
  130.         }   /* Endloop convert one bit plane */
  131.  
  132.         ++plcntr;
  133.  
  134.     }   /* Endloop convert Imagewise line */
  135.  
  136. }   /* End of toiff() */
  137.  
  138. /* End of dgiff.c */
  139.